package com.itsu.manage.controller;

import com.itsu.manage.service.AppManageUserService;
import com.itsu.pojo.vo.MessageProfileVo;
import com.itsu.pojo.vo.MsgPageResult;
import com.itsu.pojo.vo.PageResult;
import com.itsu.pojo.vo.UserProfileVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("manage")
public class ManagementController {

    @Autowired
    AppManageUserService appManageUserService;

    //用户管理-用户信息
    @GetMapping("users")
    public ResponseEntity pageUsers(@RequestParam("page") Integer page, @RequestParam("pagesize") Integer pageSize,
                                    @RequestParam("id") Long uid, @RequestParam("nickname") String nickName,
                                    @RequestParam("city") String city) {
        PageResult pageResult = appManageUserService.getPageUsers(page, pageSize, uid, nickName, city);
        return ResponseEntity.ok(pageResult);
    }

    //用户管理-用户详情
    @GetMapping("users/{id}")
    public ResponseEntity userProfile(@PathVariable Long id) {
        UserProfileVo vo = appManageUserService.getUserProfile(id);
        return ResponseEntity.ok(vo);
    }

    //用户管理-用户详情-冻结
    @PostMapping("users/freeze")
    public ResponseEntity freezeUser(@RequestBody Map<String, String> map) {
        Map<String, String> data = appManageUserService.freezeUser(map);
        return ResponseEntity.ok(data);
    }

    //用户管理-用户详情-解冻
    @PostMapping("users/unfreeze")
    public ResponseEntity unfreezeUser(@RequestBody Map<String, String> map) {
        Map<String, String> data = appManageUserService.unfreezeUser(map);
        return ResponseEntity.ok(data);
    }

    //用户管理-用户详情-登录信息
    @GetMapping("logs")
    public ResponseEntity logs(@RequestParam("page") Integer page, @RequestParam("pagesize") Integer pageSize,
                               @RequestParam("sortProp") String sortProp, @RequestParam("sortOrder") String sortOrder,
                               @RequestParam("uid") Long uid) {
        PageResult pageResult = appManageUserService.userLoginLogs(page, pageSize, sortProp, sortOrder, uid);
        return ResponseEntity.ok(pageResult);
    }


    //用户管理-用户详情-视频信息
    @GetMapping("videos")
    public ResponseEntity videos(@RequestParam("page") Integer page, @RequestParam("pagesize") Integer pageSize,
                                 @RequestParam("sortProp") String sortProp, @RequestParam("sortOrder") String sortOrder,
                                 @RequestParam("uid") Long uid) {
        PageResult pageResult = appManageUserService.userVideoLogs(page, pageSize, sortProp, sortOrder, uid);
        return ResponseEntity.ok(pageResult);
    }

    //用户管理-用户详情-视频信息 or 动态审核
    @GetMapping("messages")
    public ResponseEntity messages(@RequestParam("page") Integer page, @RequestParam("pagesize") Integer pageSize,
                                   @RequestParam("sortProp") String sortProp, @RequestParam("sortOrder") String sortOrder,
                                   @RequestParam(value = "id", required = false) Long id, @RequestParam(value = "uid", required = false) Long uid,
                                   @RequestParam(value = "sd", required = false) Long sd, @RequestParam(value = "ed", required = false) Long ed,
                                   @RequestParam(value = "state", required = false) String state) {
        MsgPageResult pageResult = appManageUserService.messageLogs(page, pageSize, sortProp, sortOrder, uid, id, sd, ed, state);
        return ResponseEntity.ok(pageResult);
    }

    //用户管理-用户详情-动态信息详情
    @GetMapping("messages/{id}")
    public ResponseEntity messagesProfile(@PathVariable String id) {
        MessageProfileVo vo = appManageUserService.messagesProfile(id);
        return ResponseEntity.ok(vo);
    }

    //用户管理-用户详情-动态评论列表
    @GetMapping("messages/comments")
    public ResponseEntity messagesComments(@RequestParam(value = "page", required = false) Integer page,
                                           @RequestParam(value = "pagesize", required = false) Integer pageSize,
                                           @RequestParam("sortProp") String sortProp,
                                           @RequestParam("sortOrder") String sortOrder,
                                           @RequestParam("messageID") String messageId) {
        PageResult pageResult = appManageUserService.messageComments(page, pageSize, sortProp, sortOrder, messageId);
        return ResponseEntity.ok(pageResult);
    }

    //用户管理-用户详情-动态置顶
    @PostMapping("messages/{id}/top")
    public ResponseEntity messagesTop(@PathVariable String id) {
        Map<String, String> data = appManageUserService.messageTop(id);
        return ResponseEntity.ok(data);
    }

    //用户管理-用户详情-动态取消置顶
    @PostMapping("messages/{id}/untop")
    public ResponseEntity messagesUnTop(@PathVariable String id) {
        Map<String, String> data = appManageUserService.messagesUnTop(id);
        return ResponseEntity.ok(data);
    }

    //动态审核-动态通过
    @PostMapping("messages/pass")
    public ResponseEntity messagesPass(@RequestBody String[] ids) {
        List<String> list = Arrays.asList(ids);
        Map<String, String> data = appManageUserService.messagesState(list, "5");
        return ResponseEntity.ok(data);
    }

    //动态审核-动态拒绝
    @PostMapping("messages/reject")
    public ResponseEntity messagesReject(@RequestBody String[] ids) {
        List<String> list = Arrays.asList(ids);
        Map<String, String> data = appManageUserService.messagesState(list, "4");
        return ResponseEntity.ok(data);
    }

    //动态审核-动态重申
    @PostMapping("messages/revocation")
    public ResponseEntity messagesRevocation(@RequestBody String[] ids) {
        List<String> list = Arrays.asList(ids);
        Map<String, String> data = appManageUserService.messagesState(list, "3");
        return ResponseEntity.ok(data);
    }


}
